 <template>
    <div style="margin-bottom: 100px;">
        <Card style="width:420px;height: 280px;margin:20px auto; ">
            <div style="text-align:center">
                <h3 style="text-align: center;">修改密码</h3>
                <Divider />
                <div class="mb20">
                    <Input v-model="oldPwd" type="password"  password placeholder="Enter your old password firstly!" style="width: 200px" />
                </div>
                <div style="margin-top: 10px"  class="mb20">
                    <Input  v-model="newPwd" type="password"  password placeholder="Enter your new password..." style="width: 200px"  />
                </div>

                <div class="mb20">
                    <el-button round type="info" style="width: 180px;" @click="open">确定</el-button>
                </div>
            </div>
        </Card>
    </div>
</template>

<script>
import {Notification} from "element-ui";
import store from "../store";
export default {
    name: 'password',
    data () {
        return {
            originPassword: null,
            oldPwd:'',
            newPwd:'',
            userId:Number,
        }
    },
    created() {
        this.userId = store.state.userInfo.adminId
        this.find();
    },
    methods: {
        find() {
            this.request({
                url: '/admin/password',
                method: 'get',
                params: {id: this.userId}
            }).then(res => {
                this.originPassword = res.password
            })
        },
        open() {
            this.$confirm('此操作将更改该账号的密码, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.enter()
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '取消更改'
                });
            });
        },
        enter(){
            this.request({
                url: '/admin/password/update',
                method: 'post',
                params: {id: this.userId, oldPassword: this.oldPwd, password: this.newPwd}
            }).then(res=>{
                Notification.success({
                    title: res.msg
                })
                this.newPwd = this.oldPwd = ''
            })
        }
    }
}
</script>

<style scoped>

</style>
